/*Cliente : Desde aca vamos a hacer todas las llamadas*/

#include "myFunctions.h"
#include "perceptron.h"

using namespace std;

int main(int argc,char *argv[]){
	Perceptron Pa,Pb,Pc;
	mdouble X;
	vector<double> Wa(3),Wb(3),Wc(3);
	vector<int>yd;
	Wa[0] = -1;	Wa[1] = 1; Wa[2] = 1; Pa.setWeights(Wa);
	Wb[0] = 1;	Wb[1] = 1; Wb[2] = 1; Pb.setWeights(Wb);
	Wc[0] = 1;	Wc[1] = 1; Wc[2] = -1; Pc.setWeights(Wc);
	genRandom("xor.txt", "xorRandomTest.txt", 10, 10000);	
		
	//test para XOR
	readFile(X,yd,"xorRandomTest.txt",true);
	int total = X.size(); 
	int errores = 0;	
	for(int i=0;i<total;i++){
		//cout<<"X: "<<X[i][0]<<", "<<X[i][1]<<", "<<X[i][2]<<endl;		
		vector<double> yi(3);
		yi[0] = -1;
		yi[1] = Pa.output(X[i]);
		yi[2] = Pb.output(X[i]);
		//cout<<"yi: "<<yi[0]<<", "<<yi[1]<<", "<<yi[2]<<endl;	
		int out = Pc.output(yi);
		//cout<<"out: "<<out<<", yd:"<<yd[i]<<endl;	
		if(not(out == yd[i]))
			errores++;
	}

	double percentage = 100-errores*100/total;
	cout<<"Hubo error en "<<errores<<" de "<<total<<" patrones, un total del "<<percentage<<"% de aciertos"<<endl;
	
	return 1;
}
